﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.WebControls;
using System.Data.SqlClient;
using EM.Lib;


namespace EM.Administration.Users
{
    public partial class Users : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Authentication ua = new Authentication();
            ua.CheckRolePageAuthentication(14, Authentication.RedirectionURLTypes.LoginPage);



            if (!IsPostBack)
            {
                FillCombo fc = new FillCombo();
            }

        }
        private DataTable GetData()
        {
            SqlCommand cmd = new SqlCommand();
            string sSQL = "";
            sSQL += @" SELECT U.USERID, U.USERDESC, U.USERCODE, U.USERPASS, 
                        U.CREDATE, U.CREUSER, U.MODDATE, U.MODUSER, U.USEREMAIL, CASE WHEN ACTIVEFLG = 'Y' THEN 'Evet' ELSE 'Hayır' END ACTIVEFLG, CASE WHEN ISADMIN = 'Y' THEN 'Evet' ELSE 'Hayır' END ISADMIN
                        FROM TBLUSER U";
            if (txtUSERNAME.Text !="")
            {
                sSQL += "  AND USERDESC LIKE @USERDESC ";
                cmd.Parameters.AddWithValue("@USERDESC", "%" + txtUSERNAME.Text + "%");
            }
            sSQL +="    ORDER BY U.USERDESC";

            cmd.CommandText = sSQL;

            DataTable dt = new DataTable();
            DataSrv dsrv = new DataSrv();

            dt = dsrv.CreateDataTable(cmd, "TBL");
            return dt;
        }

        protected void rgMaster_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
        {
            DataTable dt = GetData();
            rgMaster.DataSource = dt;

            rgMaster.MasterTableView.NoMasterRecordsText = "Kayıt bulunamadı.";
            rgMaster.StatusBarSettings.ReadyText = dt.Rows.Count + " adet kayıt bulundu.";
        }

        protected void rgMaster_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
        {
            if (e.Item.ItemType == Telerik.WebControls.GridItemType.Pager)
            {
                Label lblRecordCount = new Label();
                e.Item.Controls[0].Controls.AddAt(0, lblRecordCount);
                lblRecordCount.Text = rgMaster.StatusBarSettings.ReadyText + " | sayfaya git : ";

                rgMaster.ShowStatusBar = rgMaster.PageCount <= 1 ? true : false;
            }
        }

        protected override void RaisePostBackEvent(IPostBackEventHandler source, String eventArgument)
        {
            base.RaisePostBackEvent(source, eventArgument);
            switch (eventArgument)
            {
                case "Rebind":
                    rgMaster.Rebind();
                    break;
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            rgMaster.Rebind();

        }
    }
}
